<?php namespace Admin\Controller;

use Hdphp\Controller\Controller;

class TypeController extends CommonController{
	private $model;

	public function __construct(){
		parent::__construct();
		$this->model = new \Common\Model\Type;
	}

	public function index(){
		$data = $this->model->get();
		View::with('data',$data);
		View::make();
	}

	public function add(){
		if(IS_POST){
			if($this->model->addData(Q('post.tname'))){
				View::success('添加成功',U('index'));
			}
			View::error($this->model->getError());
		}
		View::make();
	}

	public function edit(){
		if(IS_POST){
			if($this->model->editData()){
				View::success('添加成功',U('index'));
			}
			View::error($this->model->getError());
		}
		$tid = Q('get.tid','0','intval');
		$oldData = $this->model->where("tid={$tid}")->find();
		View::with('oldData',$oldData);
		View::make();
	}

	public function del(){
		$tid = Q('get.tid','0','intval');
		$this->model->where("tid={$tid}")->delete();
		View::success('删除成功');
	}

}



 ?>